// minibossnpc.txt
// Like basicnpc, but character automatically talks to party when they get 
// within 6 spaces or combat starts. The dialogue is meant to only
// be said once, and not again. This script is meant to be for
// foes of the party.
// Memory Cells:
//   Cell 0 - How creature moves.
//     0 - If 0, wander randomly. 
//     1 - Stands still until a target appears.
//     2 - Completely immobile, even if target appears.

//   Cell 3 - Dialogue node the character talks from.


begincreaturescript;

variables;

short i,target;
short r1 = 0;
short duration = 0;
short last_abil1;
short last_abil2;
short last_abil3;
short mess1 = 0;
short mess2 = 0;
short mess3 = 0;

body;

beginstate INIT_STATE;
	//set_name(ME,"");
	//set_level(ME,);
	change_max_health(ME,200);
	set_boss_level(ME,2);
	set_coloradj(ME,0);
	set_scaling(ME,100);
	set_aggression(ME,33);
	
	set_courage(ME,100);
	set_resistance(ME,7,90);
	if (get_memory_cell(0) == 2)
		set_walk_speed(ME,0);
	last_abil1 = get_current_tick();
	last_abil2 = get_current_tick();
	last_abil3 = get_current_tick();
	break;

beginstate DEAD_STATE;
	run_game_hardcode(4);
	sf(307,3,1);
	award_party_xp(MED_QUEST_XP,6);
	ok_dlog(56,3);
	ok_dlog(59,3);

break;

beginstate START_STATE; 

		
	// if I have a target for some reason, go attack it
	if (target_ok()) {
		if (dist_to_char(get_target()) <= 16)
			set_state(3);
			else set_foe_target(ME,-1);
		}
	
	// Look for a target, attack it if visible
	if (get_foe_target(ME,8,0)) {

		if (dist_to_party() > 8)
			approach_char(ME,30000,7);
			else {
				do_attack();
				set_state(3);
				}
		}
		
	// Have I been hit? Strike back!
	if (who_shot_me() >= 0) {
		set_foe_target(ME,who_shot_me());

		do_attack();
		set_state(3);
		}

	// if we're hostile, hunt party down
	//if (get_attitude(ME) >= 10) {
	//	set_foe_target(ME,random_group_member(0));
	//	set_state(3);
	//	}		


	// if we're in combat and the above didn't give me anything to do, just
	// stop now. Otherwise, game will keep running script, and that eats up CPU time.
	if (am_i_doing_action() == FALSE)
		end_combat_turn();
break;

beginstate 3; // attacking
	duration = 1;
	if (difficulty() > 1)
		duration = 0;

	if (target_ok() == FALSE)
		set_state(START_STATE);


	// OCCASIONAL BLESS
	if ((tick_difference(last_abil1,get_current_tick()) > duration) && (gf(23,12) < 5)) {
		last_abil1 = get_current_tick();

		run_text_on_char(ME,"Brazier blessing!",0);
		print_str_color("A brazier blesses the slime beast!",2);	
		run_char_animation(3,1,35);	
		pc_heard_sound_delay(105,100);	

		if (get_char_status(ME,0) == 0)
			set_char_status(ME,0,3 + difficulty());
			else if (get_char_status(ME,4) == 0)
				set_char_status(ME,4,3 + difficulty());
			else if (get_char_status(ME,2) == 0)
				set_char_status(ME,2,3 + difficulty());
		if (gf(23,12) <= 3) {
			if (get_char_status(ME,21) == 0)
				set_char_status(ME,21,3 + difficulty());
				else if (get_char_status(ME,20) == 0)
					set_char_status(ME,20,3 + difficulty());
			}
		
		if (mess1 == 0) {
			mess1 = 1;
			ok_dlog(66,1);
			}
		end();
		}
	
	// STICK TO WALL
	if ((tick_difference(last_abil2,get_current_tick()) > duration + 2) && (num_chars_in_group(0) > 1)) {
		i = random_group_member(0);
		if (dist_to_char(i) > 2)
			i = random_group_member(0);
		if (dist_to_char(i) <= 2) {
		
			last_abil2 = get_current_tick();
	
			run_text_on_char(ME,"Fling!",0);
			run_text_on_char(i,"Aaaargh!",0);
			print_str_color("The slime beast flings away an enemy!",2);	
			run_char_animation(3,1,35);	
			pc_heard_sound_delay(89,100);	

			if (dist_to_loc(ME,26,1) > 5) {
				relocate_char(i,26,1,TRUE);
				set_foe_target(ME,-1);
				set_char_status(i,31,2 + difficulty());
				set_char_status(i,38,difficulty());
				
				r1 = get_ran(1,0,15);
				if (char_ok(2368 + r1) == FALSE) {
					spawn_creature(2368 + r1);
					relocate_char(2368 + r1,26,2,TRUE);
					}
					
				if (difficulty() > 1) {
					r1 = get_ran(1,0,15);
					if (char_ok(2368 + r1) == FALSE) {
						spawn_creature(2368 + r1);
						relocate_char(2368 + r1,27,2,TRUE);
						}
					}
				}
				else {
					relocate_char(i,26,12,TRUE);
					set_foe_target(ME,-1);
					set_char_status(i,31,2 + difficulty());
					set_char_status(i,38,difficulty());
					
					r1 = get_ran(1,0,15);
					if (char_ok(2368 + r1) == FALSE) {
						spawn_creature(2368 + r1);
						relocate_char(2368 + r1,26,13,TRUE);
						}
						
					if (difficulty() > 1) {
						r1 = get_ran(1,0,15);
						if (char_ok(2368 + r1) == FALSE) {
							spawn_creature(2368 + r1);
							relocate_char(2368 + r1,27,13,TRUE);
							}
						}
					}

			if (mess2 == 0) {
				mess2 = 1;
				ok_dlog(70,1);
				}
			end();
			}
		}
	
	// SUMMONS
	if (tick_difference(last_abil3,get_current_tick()) > duration + 1) {
		i = random_group_member(0);
		if ((dist_to_char(i) < 3) || (can_see_char(i) == FALSE))
			i = random_group_member(0);
		if ((dist_to_char(i) < 3) || (can_see_char(i) == FALSE))
			i = random_group_member(0);
		if ((dist_to_char(i) >= 3) && (can_see_char(i))) {
		
			last_abil3 = get_current_tick();
	
			run_text_on_char(ME,"Ptooooie!",0);
			run_text_on_char(i,"Goo!",0);
			print_str_color("The slime beast spits out a glob of goo!",2);	
			run_char_animation(3,1,35);	
			pc_heard_sound_delay(156,100);	

			r1 = get_ran(1,0,15);
			if (char_ok(2368 + r1)) 
				r1 = get_ran(1,0,15);
			if (char_ok(2368 + r1)) 
				r1 = get_ran(1,0,15);
			if (char_ok(2368 + r1)) 
				r1 = get_ran(1,0,15);
				
			if (char_ok(2368 + r1) == FALSE) {
				spawn_creature(2368 + r1);
				relocate_char(2368 + r1,char_loc_x(i),char_loc_y(i),TRUE);
				}
			set_char_status(i,6,1 + difficulty());

			if (mess3 == 0) {
				mess3 = 1;
				ok_dlog(68,1);
				}
			end();
			}
		}


	//	run_char_animation(3,1,35);	
	//	pc_heard_sound_delay(171,100);	
	
	//	place_particle_num(,1051,1,8);
	//run_text_on_char(short which_char_or_group,char *text,short color)
	//add_ability(, 15, which_ability, 0);
	
	//if ((mess1 == 0) && (get_health(ME) < (get_max_health(ME) * 5) / 10)) {
	//	mess1 = 1;
	//	}

	do_attack();
break;

beginstate 4; // returning to start
	if (my_dist_from_start() < 10)
		set_state(START_STATE);

	// Have I been hit? Strike back!
	if (who_shot_me() >= 0) {
		set_foe_target(ME,who_shot_me());
		do_attack();
		set_state(3);
		}
	
	return_to_start(ME,2);
break;

beginstate TALKING_STATE;
	if (get_memory_cell(3) == 0) {
		print_named_str(ME,"doesn't respond.");
		end();
		}
	talk_no_exit(get_memory_cell(3));
break;